﻿// See https://aka.ms/new-console-template for more information

using JiebaNet.Segmenter;
using JiebaNet.Segmenter.PosSeg;

string _corpusPath = Path.Combine(AppContext.BaseDirectory, "JiebaConfig");
// 定义分词路径
JiebaNet.Segmenter.ConfigManager.ConfigFileBaseDir = _corpusPath;
var segmenter = new JiebaSegmenter();


// 加载公用的词典
// 词、词频（可省略）、词性（可省略）
segmenter.LoadUserDict(Path.Combine(_corpusPath, "csname_u8.txt")); // 人名
segmenter.LoadUserDict(Path.Combine(_corpusPath, "region.txt")); // 地方名


// 加载自定义语料
segmenter.AddWord("蚁耀芳", tag: "nr");
//segmenter.AddWord("潘永和", tag: "nr");

var s = "江门韦香能转移支出";


//var tokens = segmenter.Cut(s, true);
//foreach (var p in tokens)
//{
//    Console.WriteLine($"提取到的人名：{p}");
//}


var posSeg = new PosSegmenter(segmenter);
var tokens = posSeg.Cut(s);

// 将人名连起来
var r = string.Join("", tokens.Where(p => p.Flag == "nr").Select(p => p.Word));
Console.WriteLine(r);

foreach (var p in tokens.Where(p => p.Flag == "nr"))
{
    Console.WriteLine($"提取到的人名：{p.Word}");
}
Console.WriteLine(string.Join(" ", tokens.Select(token => string.Format("{0}/{1}", token.Word, token.Flag))));
